import { router } from 'umi'
import { parseQuery } from './utils'

export function routeTo(path) {
  router.push(toPath(path))
}

export function replaceTo(path) {
  router.replace(toPath(path))
}

export function toPath(path) {
  const { layout } = parseQuery(window.location.href)
  if (layout === 'inner' && !path.includes('layout=')) {
    if (path.includes('?'))
      path = `${path}&layout=inner`
    else
      path = `${path}?layout=inner`
  }
  return path
}
